package com.ruoyi.web.controller.inspection;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.system.service.PersonPositionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.io.ClassPathResource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.*;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 人员定位(PersonnelLocalation)表控制层
 *
 * @author dlj
 * @since 2023-04-26 22:31:26
 */
@Slf4j
@RestController
@RequestMapping("person/position")
public class PersonPositionController extends BaseController {

    @Resource
    private PersonPositionService personnelLocationService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping
    public ResponseEntity<Map<String, List<BigDecimal[]>>> queryById(@RequestParam("id") Integer id) {
        Map<String, List<BigDecimal[]>> result = this.personnelLocationService.queryById(id);
        return ResponseEntity.ok(result);
    }


    @PostMapping("/list")
    public com.alibaba.fastjson2.JSONObject dataList(@RequestBody String req) {
        log.info("list:req:{}", req);
        String msg = "{\n" +
                "\t\"msg\":\"操作成功\",\n" +
                "\t\"code\":200,\n" +
                "\t\"data\":{\n" +
                "\t\t\"records\":[\n" +
                "\t\t\t{\n" +
                "\t\t\t\t\"id\": 1786\n" +
                "\t\t\t\t\"name\":\"cocof\"\n" +
                "\t\t\t\t\"sex\": null,\n" +
                "\t\t\t\t\"phone\": null\n" +
                "\t\t\t\t\"photo\":\"/\"\n" +
                "\t\t\t\t\"jobNumbex\":\"STbbf\",\n" +
                "\t\t\t\t\"tagId\": null,\n" +
                "\t\t\t\t\"post\": null,\n" +
                "\t\t\t\t\"station\": null,\n" +
                "\t\t\t\t\"security\": null,\n" +
                "\t\t\t\t\"entityIconId\": 1,\n" +
                "\t\t\t\t\"deptId\": null,\n" +
                "\t\t\t\t\"orgId\": 100,\n" +
                "\t\t\t\t\"type\": 1,\n" +
                "\t\t\t\t\"deleted\": null,\n" +
                "\t\t\t\t\"remark\": null,\n" +
                "\t\t\t\t\"fileId\": null\t\n" +
                "\t\t\t},\n" +
                "\t\t\t{\n" +
                "\t\t\t\t\"id\": 1787\n" +
                "\t\t\t\t\"name\":\"xujianming\"\n" +
                "\t\t\t\t\"sex\": null,\n" +
                "\t\t\t\t\"phone\": null\n" +
                "\t\t\t\t\"photo\":\"/\"\n" +
                "\t\t\t\t\"jobNumbex\":\"STbbf1\",\n" +
                "\t\t\t\t\"tagId\": \"BTT_0001787\",\n" +
                "\t\t\t\t\"post\": null,\n" +
                "\t\t\t\t\"station\": null,\n" +
                "\t\t\t\t\"security\": null,\n" +
                "\t\t\t\t\"entityIconId\": 1,\n" +
                "\t\t\t\t\"deptId\": null,\n" +
                "\t\t\t\t\"orgId\": 100,\n" +
                "\t\t\t\t\"type\": 1,\n" +
                "\t\t\t\t\"deleted\": null,\n" +
                "\t\t\t\t\"remark\": null,\n" +
                "\t\t\t\t\"fileId\": null\t\n" +
                "\t\t\t},\n" +
                "\t\t\t{\n" +
                "\t\t\t\t\"id\": 1788\n" +
                "\t\t\t\t\"name\":\"xuyuxing\"\n" +
                "\t\t\t\t\"sex\": null,\n" +
                "\t\t\t\t\"phone\": null\n" +
                "\t\t\t\t\"photo\":\"/\"\n" +
                "\t\t\t\t\"jobNumbex\":\"STbbf2\",\n" +
                "\t\t\t\t\"tagId\": \"BTT_0001788\",\n" +
                "\t\t\t\t\"post\": null,\n" +
                "\t\t\t\t\"station\": null,\n" +
                "\t\t\t\t\"security\": null,\n" +
                "\t\t\t\t\"entityIconId\": 1,\n" +
                "\t\t\t\t\"deptId\": null,\n" +
                "\t\t\t\t\"orgId\": 100,\n" +
                "\t\t\t\t\"type\": 1,\n" +
                "\t\t\t\t\"deleted\": null,\n" +
                "\t\t\t\t\"remark\": null,\n" +
                "\t\t\t\t\"fileId\": null\t\n" +
                "\t\t\t}\n" +
                "\t\t]\n" +
                "\t}\t\n" +
                "}";
        com.alibaba.fastjson2.JSONObject result = com.alibaba.fastjson2.JSONObject.parse(msg);
        return result;
    }

    @PostMapping("/history")
    public com.alibaba.fastjson2.JSONObject history(@RequestBody String req) throws IOException {
        log.info("history:req:{}", req);

        ClassPathResource resource = new ClassPathResource("json\\person_position_test.json");
        InputStream inputStream = resource.getInputStream();

        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
        StringBuffer msg = new StringBuffer();
        String line;
        while((line = bufferedReader.readLine()) != null){
            msg.append(line);
        }

        JSONObject result = JSON.parseObject(msg.toString(), JSONObject.class);
        log.info("result:{}", result);
        return result;
    }

}

